//
//  DistanceView.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/9/26.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "DistanceView.h"

@interface DistanceView()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSArray *titleSArray;
@end

@implementation DistanceView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self createTableView];
    }
    return self;
}

-(void)createTableView{
    self.tableView = [[UITableView alloc] initWithFrame:self.bounds];
    [self addSubview:self.tableView];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView reloadData];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.titleSArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"cellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        cell.textLabel.text = self.titleSArray[indexPath.row];
        cell.textLabel.font = [UIFont systemFontOfSize:13];
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (self.sendBlock) {
        self.sendBlock([NSString stringWithFormat:@"%ld",(long)indexPath.row]);
    }
    
}
-(NSArray *)titleSArray{
    if (_titleSArray == nil) {
        _titleSArray = @[@"智能排序",@"离我最近",@"人气最高",@"星级排序",@"按推荐排序"];
    }
    return _titleSArray;
}


@end
